

#import "HMHelp.h"

@implementation HMHelp
+(instancetype)helpWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}

-(instancetype)initWithDict:(NSDictionary *)dict{
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

+(NSArray *)helps{
    // 获得文件路径
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"help.json" ofType:nil];
    // 加载数据
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    /*
    NSJSONReadingMutableContainers = (1UL << 0), 返回的容器(数组和字典)是可变的
    NSJSONReadingMutableLeaves = (1UL << 1), 返回的容器是不可变的
    NSJSONReadingAllowFragments = (1UL << 2)
     */
    NSArray *helpArray =  [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
    NSMutableArray *helps = [NSMutableArray array];
    for (NSDictionary *dict in helpArray) {
        // 将字典转模型
        HMHelp *help = [HMHelp helpWithDict:dict];
        [helps addObject:help];
    }
    return helps;
}
@end
